package net.flintx.array;

/**
 * Created by flintx on 2018/1/14.
 */
public class LongestContinuousIncreasingSubsequence {
    public int findLengthOfLCIS(int[] nums) {
        if (nums.length < 2)
            return nums.length;
        for (int i = nums.length - 1; i > 0; i--) {
            nums[i] = (nums[i] - nums[i - 1] > 0)? 1 : -10001;
        }
        int max = Integer.MIN_VALUE, sum = 1;
        for (int i = 1; i < nums.length; i++) {
            sum += nums[i];
            if (sum < 0) {
                max = Math.max(sum + 10001, max);
                sum = 1;
            } else {
                max = Math.max(sum, max);
            }
        }
        return max;
    }

    private static int betterMethod(int[] nums) {
        if (nums.length < 2)
            return nums.length;
        int cnt = 1, max = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i - 1] > 0)
                max = Math.max(max, ++cnt);
            else
                cnt = 1;
        }
        return max;
    }

    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 4, 7};
//        System.out.println(new LongestContinuousIncreasingSubsequence().findLengthOfLCIS(nums));
        System.out.println(new LongestContinuousIncreasingSubsequence().betterMethod(nums));
    }
}
